package com.dianqiu.base.action;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.dispatcher.SessionMap;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;
import com.dianqiu.base.bean.BaseTO;
import com.dianqiu.common.bean.DqMatchHistTO;
import com.dianqiu.common.bean.DqMatchTO;
import com.dianqiu.common.service.BetService;
import com.dianqiu.common.service.BetUserMatchHistService;
import com.dianqiu.common.service.CreateMatchService;
import com.dianqiu.common.service.HandicapService;
import com.dianqiu.common.service.ListHandicapService;
import com.dianqiu.common.service.MatchHistService;
import com.dianqiu.common.service.MatchPoolService;
import com.dianqiu.common.service.MatchService;
import com.dianqiu.common.service.UserBetConfigService;
import com.opensymphony.xwork2.ActionSupport;

public class BaseForJopAction  implements ServletRequestAware, ServletResponseAware, SessionAware {
	
	private static final long serialVersionUID = 1L;
	
	private MatchPoolService matchPoolService;
	
	
	public MatchPoolService getMatchPoolService() {
		return matchPoolService;
	}
	@Resource
	public void setMatchPoolService(MatchPoolService matchPoolService) {
		this.matchPoolService = matchPoolService;
	}

	//MatchService
	private MatchService matchService;
	
	
	public MatchService getMatchService() {
		return matchService;
	}
	@Resource
	public void setMatchService(MatchService matchService) {
		this.matchService = matchService;
	}

	//HandicapService
	private HandicapService handicapService;
	
	public HandicapService getHandicapService() {
		return handicapService;
	}
	@Resource
	public void setHandicapService(HandicapService handicapService) {
		this.handicapService = handicapService;
	}

	//betUserMatchHistService
	private BetUserMatchHistService betUserMatchHistService;
	
	public BetUserMatchHistService getBetUserMatchHistService() {
		return betUserMatchHistService;
	}
	@Resource
	public void setBetUserMatchHistService(
			BetUserMatchHistService betUserMatchHistService) {
		this.betUserMatchHistService = betUserMatchHistService;
	}

	//UserBetConfigService
	private UserBetConfigService userBetConfigService;
	
	public UserBetConfigService getUserBetConfigService() {
		return userBetConfigService;
	}
	@Resource
	public void setUserBetConfigService(UserBetConfigService userBetConfigService) {
		this.userBetConfigService = userBetConfigService;
	}

	//createMatchService
	private CreateMatchService createMatchService;
	
	public CreateMatchService getCreateMatchService() {
		return createMatchService;
	}

	@Resource
	public void setCreateMatchService(CreateMatchService createMatchService) {
		this.createMatchService = createMatchService;
	}
	
	//listHandicapService
	private ListHandicapService listHandicapService;

	public ListHandicapService getListHandicapService() {
		return listHandicapService;
	}

	@Resource
	public void setListHandicapService(ListHandicapService listHandicapService) {
		this.listHandicapService = listHandicapService;
	}

	//BetService
	private BetService betService;
	
	public BetService getBetService() {
		return betService;
	}

	@Resource
	public void setBetService(BetService betService) {
		this.betService = betService;
	}

	//***********************request, response, session**********************************************//
	private HttpServletRequest request;
	
	private HttpServletResponse response;
	
	private SessionMap<String, Object> session;
	
	@Override
	public void setServletRequest(HttpServletRequest request) {
		this.request = request;
		
	}
	
	public HttpServletRequest getRequest() {
		return request;
	}


	@Override
	public void setServletResponse(HttpServletResponse response) {
		this.response = response;
		
	}
	
	public HttpServletResponse getServletResponse(){
		return response;
	}

	@Override
	public void setSession(Map<String, Object> session) {
		this.session =  (SessionMap<String, Object>) session;
		
	}

	public SessionMap<String, Object> getSession(){
		return session;
	}
	//*********************************************************************************************//
	
	private MatchHistService matchHistService;
	
	public MatchHistService getMatchHistService() {
		return matchHistService;
	}

	@Resource
	public void setMatchHistService(MatchHistService matchHistService) {
		this.matchHistService = matchHistService;
	}
	
	public BaseTO createInitialize(BaseTO obj,HttpServletRequest request){
		obj.setInd("A");
		obj.setCreatedBy("system");
		obj.setUpdatedBy("system");
		Timestamp createDate = new Timestamp(System.currentTimeMillis());
		obj.setCreatedDt(createDate);
		obj.setUpdatedDt(createDate);
		return obj;
	}
	
	public BaseTO updateInitialize(BaseTO obj,HttpServletRequest request){
		obj.setInd("A");
		obj.setUpdatedBy("system");
		Timestamp createDate = new Timestamp(System.currentTimeMillis());
		obj.setUpdatedDt(createDate);
		return obj;
	}
	//*********************************************************************************************//

	//add by david for set matchDate and matchTime in DqMatchTO begin
	public void setMatchDateAndTime(DqMatchTO dqMatchTO){
		Date dqDate = dqMatchTO.getMthDate();
		String hour = dqDate.getHours() + "";
		String minutes = dqDate.getMinutes() + "";
		String matchTime = hour + ":" + minutes;
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
		String matchDate = formatter.format(dqDate);
		dqMatchTO.setMatchDate(matchDate);
		dqMatchTO.setMatchTime(matchTime);
	}
	//add by david for set matchDate and matchTime in DqMatchTO end
	
	
	//add by david for set matchDate and matchTime in DqMatchHistTO begin
	public void setMatchHistDateAndTime(DqMatchHistTO dqMatchHistTO){
		Date dqDate = dqMatchHistTO.getMthDate();
		String hour = dqDate.getHours() + "";
		String minutes = dqDate.getMinutes() + "";
		String matchTime = hour + ":" + minutes;
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
		String matchDate = formatter.format(dqDate);
		dqMatchHistTO.setMatchDate(matchDate);
		dqMatchHistTO.setMatchTime(matchTime);
	}
	//add by david for set matchDate and matchTime in DqMatchHistTO end
	

}
